package com.smc.configuration;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.smc.sys.filter.AuthenticateFilter;

/**
 * @author zouqinghua
 * @date 2018年11月5日 上午10:25:11
 *
 */
@Configuration
public class FilterConfiguration {

	@Bean
	public FilterRegistrationBean  authenticateFilterBean() {
		FilterRegistrationBean   registration = new FilterRegistrationBean();
		// 注入过滤器
		registration.setFilter(new AuthenticateFilter());
		// 拦截规则
		registration.addUrlPatterns("/api/*");
		registration.addUrlPatterns("/mgmt/*");
		registration.addUrlPatterns("/mgmt");
		
		// 过滤器名称
		registration.setName("authenticateFilter");
		// 是否自动注册 false 取消Filter的自动注册
		//registration.setEnabled(false);
		// 过滤器顺序
		registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
		return registration;
	}

	//@Bean
	public FilterRegistrationBean  sitemeshFilterBean() {
		FilterRegistrationBean   registration = new FilterRegistrationBean();
		
		
		// 注入过滤器
		//registration.setFilter(new com.smc.sys.filter.WebSiteMeshFilter());
		// 拦截规则
		registration.addUrlPatterns("/*");
		
		// 过滤器名称
		registration.setName("sitemeshFilter");
		// 是否自动注册 false 取消Filter的自动注册
		//registration.setEnabled(false);
		// 过滤器顺序
		registration.setOrder(1);
		return registration;
	}
	
	@Bean
	public FilterRegistrationBean  opensymphonySitemeshFilterBean() {
		FilterRegistrationBean   registration = new FilterRegistrationBean();
		
		
		// 注入过滤器
		registration.setFilter(new com.opensymphony.sitemesh.webapp.SiteMeshFilter());
		
		//registration.addInitParameter("decorators-file", "/WEB-INF/deco222rators.xml");
		
		// 拦截规则
		registration.addUrlPatterns("/mgmt/*","/mgmt","/mgmt/login");
		// 过滤器名称
		registration.setName("sitemeshFilter");
		// 是否自动注册 false 取消Filter的自动注册
		//registration.setEnabled(false);
		// 过滤器顺序
		registration.setOrder(1);
		return registration;
	}
}
